package com.yiyi.word_test.service.impl;

import cn.hutool.core.util.ArrayUtil;
import com.yiyi.word_test.entity.Question;
import com.yiyi.word_test.enums.GradeEnum;
import com.yiyi.word_test.repository.QuestionRepository;
import com.yiyi.word_test.service.QuestionService;
import com.yiyi.word_test.util.CreateQuestionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionRepository questionRepository;

    // 修改后，直接获取50道题
    public List<Question> getAllQuestion(Integer grade) {
        Integer[] nums = ArrayUtil.clone(GradeEnum.values()[grade].getNums());
        List<Integer> idList = CreateQuestionUtil.createAllQuestion(nums);
        return questionRepository.findAllByIdIsIn(idList);
    }
}
